<template>
  <div class="add-blog-container">
    <h2>新增博客</h2>
    <form @submit.prevent="addBlog">
      <div>
        <label for="title">标题:</label>
        <input type="text" id="title" v-model="title" required />
      </div>
      <div>
        <label for="content">内容:</label>
        <textarea id="content" v-model="content" required></textarea>
      </div>
      <div>
        <label for="image">图片链接:</label>
        <input type="text" id="image" v-model="image" />
      </div>
      <button type="submit">添加博客</button>
    </form>
    <router-link to="/home">返回首页</router-link>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const title = ref('');
const content = ref('');
const image = ref('');

// 添加博客
const addBlog = () => {
  const newBlog = {
    title: title.value,
    content: content.value,
    image: image.value,
  };

  // 在这里可以将新博客信息存储到本地存储或发送到后端
  const blogs = JSON.parse(localStorage.getItem('blogs')) || [];
  blogs.push(newBlog);
  localStorage.setItem('blogs', JSON.stringify(blogs));

  console.log('新博客已添加:', newBlog);

  // 清空输入框
  title.value = '';
  content.value = '';
  image.value = '';
};
</script>

<style scoped>
.add-blog-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.add-blog-container h2 {
  text-align: center;
}

.add-blog-container form {
  display: flex;
  flex-direction: column;
}

.add-blog-container label {
  margin-bottom: 5px;
}

.add-blog-container input,
.add-blog-container textarea {
  padding: 10px;
  margin-bottom: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.add-blog-container button {
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.add-blog-container button:hover {
  background-color: #0056b3;
}
</style> 